//
//  LYLiveDescCell.m
//  LYLiveApp
//
//  Created by QD on 2018/6/25.
//  Copyright © 2018年 览益信息科技. All rights reserved.
//

#import "LYLiveDescCell.h"
#import "LYTeacherModel.h"

@interface LYLiveDescCell ()
@property (weak, nonatomic) IBOutlet UIImageView *headerImg;
@property (weak, nonatomic) IBOutlet UILabel *nameLabel;
@property (weak, nonatomic) IBOutlet UILabel *styleLabel;
@property (weak, nonatomic) IBOutlet UILabel *descLabel;
@property (weak, nonatomic) IBOutlet NSLayoutConstraint *descLabelHeight;
@property (weak, nonatomic) IBOutlet NSLayoutConstraint *nameLabelWidth;
@property (weak, nonatomic) IBOutlet UIButton *joinTeamBtn;
@property (weak, nonatomic) IBOutlet NSLayoutConstraint *joinTeamBtnWidth;

@end

@implementation LYLiveDescCell

- (void)awakeFromNib {
    [super awakeFromNib];
    
    self.joinTeamBtn.backgroundColor = HEX(@"#F16B6F");

}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

}

+ (instancetype)viewWithXib
{
    LYLiveDescCell *view = [[[UINib nibWithNibName:@"LYLiveDescCell" bundle:nil] instantiateWithOwner:self options:nil] lastObject];
    return view;
}

- (void)setTeacherModel:(LYTeacherModel *)teacherModel {
    
    _teacherModel = teacherModel;
    [self.headerImg sd_setImageWithURL:[NSURL URLWithString:teacherModel.avatar] placeholderImage:[UIImage imageNamed:@"avatar_default"]];
    self.nameLabel.text = [NSString stringWithFormat:@"%@",teacherModel.nickname];
    self.nameLabelWidth.constant = [LYUtil sizeWithText:self.nameLabel.text font:self.nameLabel.font withWidth:200].width + 5;

    self.styleLabel.text = teacherModel.style;
    self.descLabel.text = teacherModel.desc;

    CGFloat contentHeight = [LYUtil sizeWithText:teacherModel.desc font:self.descLabel.font withWidth:SCREEN_WIDTH - 62].height;
    self.descLabelHeight.constant = contentHeight;
    self.height = 55 + contentHeight;
    teacherModel.viewHeight = 55 + contentHeight;
    
    if ([LYLocalData sharedInstance].imStatus.integerValue == 2) {
        [self.joinTeamBtn setTitle:[LYLocalData sharedInstance].imText forState:UIControlStateNormal];
        UIFont *font = [UIFont fontWithName:@"PingFangSC-Regular" size:12.0f];
        self.joinTeamBtnWidth.constant = [LYUtil sizeWithText:[LYLocalData sharedInstance].imText font:font withWidth:200].width + 15;
        self.joinTeamBtn.hidden = NO;
    } else {
        self.joinTeamBtn.hidden = YES;
    }
}

#pragma mark ----- Event Response

- (IBAction)joinTeamAction:(id)sender {
    
    !self.joinTeamBlock?:self.joinTeamBlock();
}

@end
